package com.yangye.pisystem.controller;

import com.yangye.picommon.model.PiResult;
import com.yangye.picommon.utils.JwtTokenUtil;
import com.yangye.pisystem.domain.SysUser;
import com.yangye.pisystem.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by yangye on 2019/7/4
 */
@RestController
public class LoginController {

	@Autowired
	private JwtTokenUtil jwtTokenUtil;
	@Autowired
	private SysUserService sysUserService;

	@GetMapping("/auth/user")
	PiResult getUserInfo(@RequestHeader("Authorization") String token) {
		String usernameFromToken = jwtTokenUtil.getUsernameFromToken(token);
		SysUser user = sysUserService.findByUsername(usernameFromToken);
		return PiResult.succeed(user);
	}

}
